home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Animation Class Library / Examples / ACL-World / Sources / Controls.cp < prev    next >
Encoding:
Text File  |  1994-09-02  |  3.8 KB  |  175 lines  |  [TEXT/MMCC]

  1.  
  2. /********************************************
  3.  **** ACL-World
  4.  ****
  5.  **** Controls.cp
  6.  ****
  7.  **** Created:      25 August 1994
  8.  **** Modified:     29 August 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:    Controls demo.
  13.  ****
  14.  *******************/
  15.  
  16. #include "ACL-World.h"
  17.  
  18. //*************************************
  19.  
  20.  
  21. static const short PICT_BACKGROUND     = 142;
  22. static const short PICT_BACKGROUND2 = 147;
  23. static const short PICT_BACKGROUND3 = 148;
  24.  
  25.  
  26. //*************************************
  27.  
  28. #define    TEXTSTEP1    "\pA control is a chain of commands which can be linked to any ACL moveable object. There are several different commands. Click in the picture to see a \"go to\" command."
  29.  
  30. #define    TEXTSTEP2    "\pACL defines also a \"curve\" command. Speed and acceleration may be defined for \"curve\" and \"go to\" commands. Click anywhere in this picture to see the curve path. The object will go through the center of the picture and accelerate to the spot you clicked."
  31.  
  32. #define    TEXTSTEP3    "\pCommands can be chained and a loop can be inserted in the chain. When a list of commands is linked to an object, ACL processes it automatically."
  33.  
  34. #define    TEXTSTEP4    "\pACL supports several commands which allow the user to build specific and complex command chains. An user method can be linked to each command in the chain allowing a dynamic execution of the controls."
  35.                     
  36.                          
  37.                     
  38. //*************************************
  39.  
  40. static AnimGfx    *background;
  41. static short    backwidth,backheight;
  42. static Anim        *anims[1];
  43.  
  44. static AnimControl    controls[1];
  45.  
  46. //*************************************
  47.  
  48. Boolean ACLWorld::controls_advance(void)
  49. {
  50.     short     i;
  51.     Handle     ha;
  52.     Rect    rect;
  53.  
  54.     static short w,h;
  55.  
  56.     step++;
  57.     
  58.     GetDItem(dialog,1,&i,&ha,&rect);
  59.     
  60.     switch(step)
  61.     {
  62.         case 1:
  63.         SetIText(ha,TEXTSTEP1);
  64.         animbase->installbackground(background);
  65.         animbase->settupdate(1);
  66.         
  67.         anims[0] = animbase->createanim(animpers);
  68.         anims[0]->setsequence(2);
  69.         anims[0]->findmaxsize(&w,&h);
  70.         anims[0]->arrange_moveframeoffsets(2, -(w/2),-(h/2));
  71.         anims[0]->place(140,90);
  72.         
  73.         controls[0].cmd = acmd_goto;
  74.         controls[0].speed = 4;
  75.         controls[0].acceleration = 0;
  76.         controls[0].next = NULL;
  77.         return FALSE;
  78.  
  79.         case 2:
  80.         SetIText(ha,TEXTSTEP2);
  81.         anims[0]->stopcontrol();        
  82.         controls[0].cmd = acmd_curve;
  83.         controls[0].cx = backwidth/2;
  84.         controls[0].cy = backheight/2;
  85.  
  86.         return FALSE;
  87.  
  88.         case 3:
  89.         SetIText(ha,TEXTSTEP3);
  90.         delete anims[0];
  91.         animbase->installbackground(PICT_BACKGROUND2);        
  92.         return FALSE;
  93.  
  94.         case 4:
  95.         SetIText(ha,TEXTSTEP4);
  96.         animbase->installbackground(PICT_BACKGROUND3);        
  97.         return FALSE;
  98.         
  99.     }
  100.     
  101.     
  102.     return TRUE;
  103. }
  104.  
  105.  
  106.  
  107. //*************************************
  108.  
  109. Boolean ACLWorld::do_controls(void)
  110. {
  111.     Point p;
  112.     char  key;
  113.     short res;
  114.     Boolean done = FALSE;
  115.  
  116.     pleasewait(TRUE);
  117.  
  118.     animbase = new AnimBase();
  119.     
  120.     background = animbase->newgfx(PICT_BACKGROUND);
  121.     animbase->newgfx(PICT_BACKGROUND2);
  122.     animbase->newgfx(PICT_BACKGROUND3);
  123.     animbase->preload_framedef(animpers);
  124.  
  125.  
  126.     backwidth = background->getwidth();
  127.     backheight = background->getheight();
  128.         
  129.     animbase->buildbuffer(460,217);
  130.     animbase->setbasex(17);
  131.     animbase->setbasey(8);
  132.  
  133.  
  134.     pleasewait(FALSE);
  135.  
  136.     step = 0;
  137.     openbasedialog();
  138.     SetWTitle(dialog,"\pControls");
  139.     controls_advance();
  140.  
  141.     
  142.     for(;;)
  143.     {
  144.         res = processbasedialog(key,p);
  145.         
  146.         if         (res==DO_QUIT) {done=TRUE; break;}
  147.         else if (res==DO_MENU) break;
  148.         else if (res==DO_CONTINUE && controls_advance()) break;
  149.         else if (res==DO_MOUSECLICK && (step==1 || step==2))
  150.         {
  151.             if (p.h<460 && p.v<217 && p.h>=0 && p.v>=0)
  152.             {
  153.                 anims[0]->stopcontrol();
  154.                 controls[0].x = p.h;
  155.                 controls[0].y = p.v;
  156.                 if (step==2)
  157.                 {
  158.                     controls[0].speed = 1;
  159.                     controls[0].acceleration = 0.25;
  160.                 }
  161.                 
  162.                 anims[0]->runcontrol(controls);
  163.             }
  164.         }
  165.     }
  166.     
  167.     closebasedialog();
  168.     
  169.     delete animbase;
  170.  
  171.     return done;
  172. }
  173.  
  174. //*************************************
  175.